package com.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.device.domain.entity.Codenum;
import com.device.mapper.CodenumMapper;

import com.device.service.CodenumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CodenumServiceImpl extends ServiceImpl<CodenumMapper, Codenum> implements CodenumService {
    @Autowired
    private CodenumMapper codenumMapper;

    /**
     * 柜机编号
     */
    @Override
    public Integer getCabinetCode(String cabinet) {
        QueryWrapper<Codenum> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("title",cabinet);
        Codenum one = getOne(queryWrapper);
        if (one == null){
            one = new Codenum(null,cabinet,0);
            save(one);
        }
        int i = one.getSeq() + 1;
        one.setSeq(i);
        codenumMapper.updateById(one);
        return i;
    }
}
